package com.luo.dao.impl;

import com.luo.dao.ClassMappers;
import com.luo.model.Goods;
import com.luo.model.OneClass;
import com.luo.model.OneTwoClass;
import com.luo.model.TwoClass;
import com.luo.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/1/9 17:28
 */
public class ClassDaoImpl implements ClassMappers {
    @Override
    public List<OneClass> queryAllOneClass() {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        List<OneClass> oneClasses = mapper.queryAllOneClass();
        sqlSession.close();
        return oneClasses;
    }

    @Override
    public List<TwoClass> queryAllTwoClass() {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        List<TwoClass> twoClasses = mapper.queryAllTwoClass();
        sqlSession.close();
        return twoClasses;
    }

    @Override
    public List<OneClass> queryLimitOneClass() {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        List<OneClass> oneClasses = mapper.queryLimitOneClass();
        sqlSession.close();
        return oneClasses;
    }

    @Override
    public List<TwoClass> queryTwoClassByOneId(OneClass oneClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        List<TwoClass> twoClasses = mapper.queryTwoClassByOneId(oneClass);
        sqlSession.close();
        return twoClasses;
    }

    @Override
    public List<OneTwoClass> queryOneTwoClassByOneId(final OneClass oneClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        List<OneTwoClass> oneTwoClasses = mapper.queryOneTwoClassByOneId(oneClass);
        sqlSession.close();
        return oneTwoClasses;
    }

    @Override
    public OneClass queryOneClassByOneId(final String id) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        OneClass oneClass = mapper.queryOneClassByOneId(id);
        sqlSession.close();
        return oneClass;
    }

    @Override
    public List<Goods> queryGoodsByOneId(OneClass oneClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        List<Goods> goods = mapper.queryGoodsByOneId(oneClass);
        sqlSession.close();
        return goods;
    }

    @Override
    public List<TwoClass> queryTwoClassByOneName(final String name) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        List<TwoClass> twoClasses = mapper.queryTwoClassByOneName(name);
        sqlSession.close();
        return twoClasses;
    }

    @Override
    public String queryOneClassByName(String name) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        String s = mapper.queryOneClassByName(name);
        sqlSession.close();
        return s;
    }

    @Override
    public String queryTwoClassByName(String name) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        String s = mapper.queryTwoClassByName(name);
        sqlSession.close();
        return s;
    }

    @Override
    public TwoClass queryTwoClassByTwoId(final String id) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        TwoClass twoClass = mapper.queryTwoClassByTwoId(id);
        sqlSession.close();
        return twoClass;
    }

    @Override
    public int AddOneClass(final OneClass oneClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        int i = mapper.AddOneClass(oneClass);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int AddTwoClass(final TwoClass twoClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        int i = mapper.AddTwoClass(twoClass);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int deleteOneClass(List<String> list) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        int i = mapper.deleteOneClass(list);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int deleteTwoClass(List<String> list) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        int i = mapper.deleteTwoClass(list);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int updateOneClass(final OneClass oneClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        int i = mapper.updateOneClass(oneClass);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int updateTwoClass(final TwoClass twoClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassMappers mapper = sqlSession.getMapper(ClassMappers.class);
        int i = mapper.updateTwoClass(twoClass);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }
}
